package com.yonyou.iuap.jxzy.ref.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yonyou.iuap.ref.model.RefViewModelVO;

/**
 * 物料参照查询
 * @author 21559
 *
 */
@Controller
@RequestMapping(value="/materialref")
public class MaterialRefController extends AbstractBillRefModel{
	

	@Override
	public String[] getStrFieldCode() {
		return new String[]{"code","name"};
	}

	@Override
	public String getTableName() {
		return " bd_material_v ";
	}

	@Override
	public String[] getStrFieldName() {
		return new String[]{"编码","名称"};
	}

	@Override
	public String getRefCode() {
		return "code";
	}

	@Override
	public String getRefName() {
		return "name";
	}

	@Override
	public String getRefID() {
		return " pk_material ";
	}

	@Override
	public String getWhereSQL(RefViewModelVO refModel) {
		String sysId = refModel.getSysId();
		String where =" and dr = 0 and def20='Y'";
		if("type1".equals(sysId) || ((sysId!=null && sysId.contains("type1")))){//国费
			where+=" and pk_marbasclass in (select pk_marbasclass from bd_marbasclass where code = '0401') ";
		}else if("type2".equals(sysId) || ((sysId!=null && sysId.contains("type2")))){//进口,木浆
			where+=" and pk_marbasclass not in (select pk_marbasclass from bd_marbasclass where code = '0401') ";
		}else if("type3".equals(sysId) || ((sysId!=null && sysId.contains("type3")))){//固废
			where+=" and pk_marbasclass in (select pk_marbasclass from bd_marbasclass where code = '0905') ";
		}
		return where;
	}

	@Override
	public List<Map<String, Object>> getRefData(RefViewModelVO refModel) {
		return super.getRefData(refModel);
	}

	@Override
	public Map<String, Object> blobRefSearch(RefViewModelVO refModel) {
		String sysId = refModel.getSysId();
		if("app".equals(sysId) || (sysId!=null && sysId.contains("app") )){
			List<Map<String,Object>> results = getRefData(refModel);
			Map<String, Object> mapList = new HashMap();
			mapList.put("detailMsg", results);
			mapList.put("message", "操作成功");
			mapList.put("success", "success");
			return mapList;
		}
		return super.blobRefSearch(refModel);
	}
	
	
}
